import request from "@/utils/request";
//某个spu列表的销售属性列表中的销售属性值的每一项类型
export interface spuSaleAttrValueItemType {
  id?: number;
  isChecked?: number;
  spuId?: number;
  baseSaleAttrId: number; //当前spu销售属性的id
  saleAttrName: string; //当前销售属性值所在的销售属性名称
  saleAttrValueName: string; // 当前spu销售属性值的名字
}

//某个spu列表的销售属性列表中的销售属性值列表的类型
export type spuSaleAttrValueListType = spuSaleAttrValueItemType[];

//某个spu列表的销售属性列表中每一项的类型
export interface spuSaleAttrItemType {
  id?: number;
  spuId?: number;
  baseSaleAttrId: number; //当前spu销售属性在整个完整的销售属性中的id
  saleAttrName: string; //当前销售属性的名称
  spuSaleAttrValueList: spuSaleAttrValueListType;
  isEdit?: boolean;
  inputValue?: string;
  saleAttrIdValueId?: string;
}
//某个spu列表的销售属性列表类型
export type spuSaleAttrListType = spuSaleAttrItemType[];

//spu详情列表中图片列表的每一项的类型
export interface spuImageItemType {
  id?: number;
  spuId?: number;
  imgName: string;
  imgUrl: string;
  isSelect?: boolean;
  isDefault?: boolean;
}

//spu详细列表中图片列表的类型
export type spuImageListType = spuImageItemType[];

//spu详情列表的每一项的数据类型(新增时我们新添加的spu数据类型)
export interface spuInfoItemType {
  id?: number;
  spuName: string;
  description: string;
  category3Id: number;
  tmId: number | null;
  spuSaleAttrList: null | spuSaleAttrListType;
  spuImageList: null | spuImageListType;
}

//spu详情列表的数据
export type spuInfoListType = spuInfoItemType[];

//spu分页列表的数据类型
export interface spuListPageType {
  records: spuInfoListType;
  total: number;
  size: number;
  current: number;
  searchCount: boolean;
  pages: number;
}

//销售属性名称类型
export interface saleAttrItemType {
  id: number;
  name: string;
}

//销售属性名称列表类型
export type saleAttrListType = saleAttrItemType[];

//1.发送spu分页列表请求
export const reqSpuList = (
  page: number,
  limit: number,
  category3Id: number
) => {
  return request.get<null, spuListPageType>(
    `/admin/product/${page}/${limit}?category3Id=${category3Id}`
  );
};

//2. 请求所有的销售属性列表
export const reqAllSaleAttrList = () => {
  return request.get<null, saleAttrListType>(`/admin/product/baseSaleAttrList`);
};

//3. 新增spu
export const reqAddSpu = (spuInfo: spuInfoItemType) => {
  return request.post(`/admin/product/saveSpuInfo`, spuInfo);
};

//4. 根据某一个spuId获取它的图片列表
export const reqImageListBySpuId = (spuId: number) => {
  return request.get<null, spuImageListType>(
    `/admin/product/spuImageList/${spuId}`
  );
};

//5. 根据某一个spuId获取它的销售属性列表
export const reqSaleAttrBySpuId = (spuId: number) => {
  return request.get<null, spuSaleAttrListType>(
    `/admin/product/spuSaleAttrList/${spuId}`
  );
};

//6. 修改spu
export const reqUpdateSpu = (spuInfo: spuInfoItemType) => {
  return request.post(`/admin/product/updateSpuInfo`, spuInfo);
};

//7. 删除某个spu
export const reqDeleteSpu = (spuId: number) => {
  return request.delete(`/admin/product/deleteSpu/${spuId}`);
};
